package com.netintech.service;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

public class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {
    private static final Logger logger = LoggerFactory.getLogger(ServerChannelInitializer.class);
    @Override
    protected void initChannel(SocketChannel channel) throws Exception {
        logger.info("报告：有一客户端连接到本服务端---IP:"+channel.localAddress().getAddress()+"---Port:"+channel.localAddress().getPort());
        //服务端心跳检测；10秒内没数据则进行心跳处理
        ChannelPipeline cp = channel.pipeline();
        cp.addLast(new IdleStateHandler(6, 0, 0, TimeUnit.SECONDS));

        channel.pipeline().addLast("decoder",new Decoder());
//        channel.pipeline().addLast("encoder",new StringEncoder(CharsetUtil.UTF_8));
        channel.pipeline().addLast(new ServerHandler());

    }
}